import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../common/constants.dart';

import '../controllers/edit_username_controller.dart';
import '../utils/screen_util.dart';

class EditNicknamePage extends GetView<EditUsernameController> {
  const EditNicknamePage({super.key});

  @override
  Widget build(BuildContext context) {
    double height = 210;
    double y = (ScreenUtil.getScreenHeight(context) - height) * 0.5;
    final keyboardHeight = MediaQuery.of(context).viewInsets.bottom;
    final keyboardVisible = keyboardHeight > 0;
    var distance = keyboardHeight - y;
    if (distance > 0) {
      y = keyboardVisible ? y - distance - 10 : y;
    }
    return Scaffold(
      backgroundColor: Colors.black.withAlpha(127),
      resizeToAvoidBottomInset: false,
      body: GetBuilder<EditUsernameController>(builder: (_) {
        return Stack(
          children: [
            GestureDetector(
              behavior: HitTestBehavior.opaque,
              onTap: () {
                controller.focusNode.unfocus();
              },
            ),
            Container(
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(16),
              ),
              margin: EdgeInsets.symmetric(horizontal: 20, vertical: y),
              width: double.infinity,
              height: height,
              child: Column(
                children: [
                  const SizedBox(height: 16),
                  const Text("修改昵称", style: TextStyle(color: Colors.black87, fontWeight: FontWeight.bold, fontSize: 24)),
                  const SizedBox(height: 16),
                  Padding(
                    padding: EdgeInsets.symmetric(horizontal: 16),
                    child: TextField(
                        focusNode: controller.focusNode,
                        cursorColor: Colors.blue,
                        decoration: InputDecoration(
                            hintText: '搜索内容/角色',
                            hintStyle: const TextStyle(color: Colors.black38),
                            border: OutlineInputBorder(
                              borderRadius: BorderRadius.circular(12.0),
                              borderSide: BorderSide(color: Colors.red, width: 1),
                            ),
                            focusedBorder: OutlineInputBorder(
                              borderRadius: BorderRadius.circular(12.0),
                              borderSide: BorderSide(color: Constants.themeColor, width: 1),
                            ),
                            enabledBorder: OutlineInputBorder(
                              borderRadius: BorderRadius.circular(12.0),
                              borderSide: BorderSide(color: Colors.black12, width: 1),
                            ),
                            contentPadding: const EdgeInsets.symmetric(horizontal: 10, vertical: 11)),
                        style: const TextStyle(fontSize: 16),
                        onChanged: (query) {
                          print('Search query: $query');
                        },
                        onSubmitted: (text) {}),
                  ),
                  const SizedBox(
                    height: 2,
                  ),
                  Text(
                    "昵称不能包含标点符号等特殊字符和空格",
                    style: TextStyle(color: Colors.black26),
                  ),
                  Container(
                    margin: EdgeInsets.symmetric(horizontal: 16, vertical: 10),
                    width: double.infinity,
                    child: FilledButton(
                      onPressed: () {},
                      style: FilledButton.styleFrom(backgroundColor: Constants.themeColor),
                      child: Text(
                        "保存",
                        style: TextStyle(fontSize: 16),
                      ),
                    ),
                  )
                ],
              ),
            )
          ],
        );
      }),
    );
  }
}
